package cn.edu.hit.education.labelprovider;

import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

import cn.edu.hit.education.pojo.Course;

public class CourseScheduleLabelProvider extends LabelProvider implements
		ITableLabelProvider {
	/*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" );*/
	
	@Override
	public String getColumnText(Object element, int columnIndex) {
		// TODO Auto-generated method stub
		Course data = (Course) element;
		String unitName = data.getUnit() == null ?  "" : data.getUnit();
		if (columnIndex == 0) {
			return data.getNumber()==null?"":data.getNumber();
		}else if (columnIndex == 1) {
			return data.getName();
		}else if (columnIndex == 2) {
			return String.valueOf(data.getCredits());
		}else if (columnIndex == 3) {
			if(data.getMethod() != null && data.getMethod().trim().equals("分散")){
				return "(" + String.valueOf(data.getPeriod()==null?"":data.getPeriod()) + ") " + unitName;
			}else{
				return String.valueOf(data.getPeriod()==null?"":data.getPeriod()) + " " + unitName;
			}
		}else if (columnIndex == 4) {
			if(data.getMethod() != null && data.getMethod() != null && data.getMethod().trim().equals("分散")){
				return "(" + String.valueOf(data.getTheoretical()==null?"":data.getTheoretical()) + ") " + unitName;
			}else{
				return String.valueOf(data.getTheoretical()==null?"":data.getTheoretical()) + " " + unitName;
			}
		}else if (columnIndex == 5) {
			if(data.getMethod() != null && data.getMethod() != null && data.getMethod().trim().equals("分散")){
				return "(" + String.valueOf(data.getExperiment()==null?"":data.getExperiment()) + ") " + unitName;
			}else{
				return String.valueOf(data.getExperiment()==null?"":data.getExperiment()) + " " + unitName;
			}
		}else{
			return "";
		}
	}

	public Image getColumnImage(Object obj, int index) {
		return null;
	}

	public Image getImage(Object obj) {
		return PlatformUI.getWorkbench().getSharedImages()
				.getImage(ISharedImages.IMG_OBJ_ELEMENT);
	}
}